API Documentation
Public Member Functions | List of all members
nkScripts::Function Class Reference

Holds information, and controls, over a function in a scripting environment. More...

Public Member Functions

OutputValue defaultFunction (const DataStack &stack)
 The default place holder function. Set by default.
 
 Function (const char *name)
 
virtual ~Function ()
 
const char * getName () const
 
void addParameter (FUNCTION_PARAMETER_TYPE type, const char *userTypeName="")
 
void setFunction (FunctionCallback function)
 
void reset ()
 

Detailed Description

Holds information, and controls, over a function in a scripting environment.

Usage is to declare the function in the environment, sets its callback and parameters. Whenever a script will call the function, it will check and fill with parameter the stack and call the callback. Callback can then return whatever it needs to returns after processing, and this will be used within the environment.

Here is a high level overview of the usage :

Function* func = environment->setFunction("add") ; func->setCallback(addCallback) ; func->addParameter(FUNCTION_PARAMETER_TYPE::INT) ; func->addParameter(FUNCTION_PARAMETER_TYPE::STRING) ;

local x = add(5, "p") ;

OutputValue addCallback (const DataStack& stack) { int param0 = stack[0]._valInt ; const std::string& param1 = stack[1]._valString ; return OutputValue(param1 + std::to_string(param0)) ; }

print(x) ; > p5

Constructor & Destructor Documentation

◆ Function()

nkScripts::Function::Function ( const char *  name)

Constructor.

Parameters
nameThe name of the function.

◆ ~Function()

virtual nkScripts::Function::~Function ( )
virtual

Destructor.

Member Function Documentation

◆ getName()

const char* nkScripts::Function::getName ( ) const
Returns
The name of the function.

◆ addParameter()

void nkScripts::Function::addParameter ( FUNCTION_PARAMETER_TYPE  type,
const char *  userTypeName = "" 
)

Adds a parameter in the function signature.

Parameters
typeThe parameter type.
userTypeNameIf user data, the type awaited.

◆ setFunction()

void nkScripts::Function::setFunction ( FunctionCallback  function)

Sets the callback function when this function is called in script.

Parameters
functionThe function to call.

◆ reset()

void nkScripts::Function::reset ( )

Resets and starts back from an empty function.


The documentation for this class was generated from the following file: